package entities;

/*
 * version 2.0 by Bush
 * 		1. fixed the bug in checkSchedule()
 * version 1.0
 */

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;

import smallTools.SimpleTime;

public class Staff {

	private String id;
	private ArrayList<String> m_arrSectionIds = new ArrayList<String>();
	private static HashMap<String, Staff> m_mapAllStaffs = new HashMap<String, Staff>();

	// Constructor
	public Staff(String id) {

		this.id = id;
		if (m_mapAllStaffs.get(id) == null)
			m_mapAllStaffs.put(id, this);
	}

	public void addNewSection(String sectionID) {
		this.m_arrSectionIds.add(sectionID);
	}

	// Return the Staff with the given id
	public static Staff getStaffById(String id) {
		return m_mapAllStaffs.get(id);
	}

	public String getStaffId() {
		return this.id;
	}

	public static void clear() {
		m_mapAllStaffs.clear();
	}

	public ArrayList<String> getAllSectionIds() {
		this.sortSectionByStartTime();
		return this.m_arrSectionIds;
	}

	@SuppressWarnings("unchecked")
	public void sortSectionByStartTime() {
		Collections.sort(m_arrSectionIds, new byStartTime());
	}

	@SuppressWarnings("rawtypes")
	public class byStartTime implements java.util.Comparator {
		public int compare(Object o1, Object o2) {
			SimpleTime startTime1 = Section.getSectionById((String) o1)
					.getSectionStartTime();
			SimpleTime startTime2 = Section.getSectionById((String) o2)
					.getSectionStartTime();

			if (startTime1 == null || startTime2 == null)
				return 0;
			else
				return startTime1.toInt() - startTime2.toInt();
		}
	}
}